//
//  THUrlRouterManage.m
//  THBaseApp
//
//  Created by TryHone on 16/12/27.
//  Copyright © 2016年 TryHone. All rights reserved.
//

#import "JFUrlRouterManage.h"

@interface AWUrlRouterModel : NSObject

@end

@implementation AWUrlRouterModel

@end

@implementation JFUrlRouterManage{
      NSMutableDictionary * _vcDataSource;//控制器
}
+(JFUrlRouterManage *)shareInstance
{
    static dispatch_once_t once;
    static id instance;
    dispatch_once(&once, ^{
        instance = [[self alloc]init];
    });
    return instance;
}
-(instancetype)init{
    self=[super init];
    if (self) {
        _vcDataSource=[[NSMutableDictionary alloc] init];
    }
    return  self;
}
/**
 *  @author Alan, 16-12-27 10:12:56
 *
 *  @brief 添加控制器到导航管理器
 *
 *  @param jumpidenfication 控制器唯一标识(各模块请保持不一样 模块名+功能+XXX)控制器唯一标识一样会导致不可预知的问题请注意
 *  @param vcname           控制器类名
 */
+(void)addVcWithJumpidenfication:(NSString*)jumpidenfication vcName:(NSString*)vcname{
    [[JFUrlRouterManage shareInstance]addVc:jumpidenfication vcName:vcname];
}
/**
 *  @author Alan, 16-12-27 10:12:27
 *
 *  @brief 从单个文件添加控制器到导航管理器
 *
 *  @param path 文件路径(本地路径不能是http的服务路径)
 */
+(void)addVcFromPath:(NSString*)path{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSMutableArray *dataArr = [[NSMutableArray alloc] initWithContentsOfFile:path];
        if (dataArr&&dataArr.count) {
            for (NSDictionary * dict in dataArr) {
                NSString*jumpidenfication=dict[@"idf"];//跳转标识
                NSString*vcname=dict[@"vc"];//控制器名字
                [[JFUrlRouterManage shareInstance] addVc:jumpidenfication vcName:vcname];
            }
        }
    });
}

/**
 *  @author Alan, 16-12-27 10:12:27
 *
 *  @brief 从单个文件添加控制器到导航管理器
 *
 */
+(void)addVcFromPathArr:(NSArray*)pathArr{
    
    if (pathArr&&pathArr.count) {
        for (NSString*path in pathArr) {
            if (path&&path.length) {
              [JFUrlRouterManage addVcFromPath:path];
            }
        }
    }
}

/**
 *  @author Alan, 16-12-27 11:12:09
 *
 *  @brief 根据标识获取控制器
 *
 *  @param jumpidenfication 控制器标识
 *
 *  @return 返回控制器
 */
+(NSString *)vcWithIdenfication:(NSString*)jumpidenfication{
    return [[JFUrlRouterManage shareInstance] vcWithIdenfication:jumpidenfication];
}

#pragma mark--内部方法
-(NSString *)vcWithIdenfication:(NSString*)jumpidenfication{
    NSString* idf=jumpidenfication;
    if (idf&&idf.length) {
        NSString* intclassStr=[_vcDataSource objectForKey:idf];
        return intclassStr;
    }else{
        return nil;
    }
}

-(void)addVc:(NSString*)jumpidenfication vcName:(NSString*)vcname{
    if (jumpidenfication&&jumpidenfication.length) {
        if (vcname&&vcname.length)
        {
            [_vcDataSource setObject:vcname forKey:jumpidenfication];
        }
    }
}
@end
